package com.eastfair.venueservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.venueservice.dto.HomeBuilderDrawingCategoryAuditHistoryDTO;
import com.eastfair.venueservice.dto.HomeBuilderDrawingCategoryAuditHistoryPageQuery;
import com.eastfair.venueservice.dto.HomeBuilderDrawingCategoryAuditHistorySaveDTO;
import com.eastfair.venueservice.dto.HomeBuilderDrawingCategoryAuditHistoryUpdateDTO;
import com.eastfair.venueservice.entity.HomeBuilderDrawingCategoryAuditHistory;
import com.eastfair.venueservice.service.HomeBuilderDrawingCategoryAuditHistoryService;
import com.eastfair.venueservice.vo.HomeBuilderDrawingCategoryAuditHistoryVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 主场搭建商图纸分类审核历史
 * </p>
 *
 * @author dqq
 * @date 2023-05-04
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/homeBuilderDrawingCategoryAuditHistory")
@Api(value = "HomeBuilderDrawingCategoryAuditHistory", tags = "主场搭建商图纸分类审核历史")
@PreAuth(replace = "venueservice:homeBuilderDrawingCategoryAuditHistory:")
public class HomeBuilderDrawingCategoryAuditHistoryController extends SuperController<HomeBuilderDrawingCategoryAuditHistoryService, Long, HomeBuilderDrawingCategoryAuditHistory, HomeBuilderDrawingCategoryAuditHistoryPageQuery, HomeBuilderDrawingCategoryAuditHistorySaveDTO, HomeBuilderDrawingCategoryAuditHistoryUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private HomeBuilderDrawingCategoryAuditHistoryService homeBuilderDrawingCategoryAuditHistoryService;

    @Override
    public void handlerResult(IPage<HomeBuilderDrawingCategoryAuditHistory> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<HomeBuilderDrawingCategoryAuditHistory> homeBuilderDrawingCategoryAuditHistoryList = list
                .stream()
                .map((map) -> HomeBuilderDrawingCategoryAuditHistory.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(homeBuilderDrawingCategoryAuditHistoryList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<HomeBuilderDrawingCategoryAuditHistoryPageQuery> params) {
        HomeBuilderDrawingCategoryAuditHistoryPageQuery pageQuery = params.getModel();
    }

    /**
     * 分页查询审核历史.
     *
     * @param pageParams the page params
     * @return the r
     */
    @PostMapping("/query/history")
    public R<Page<HomeBuilderDrawingCategoryAuditHistoryVO>> queryHistory(@RequestBody PageParams<HomeBuilderDrawingCategoryAuditHistoryDTO> pageParams) {
        log.info("queryHistory - 分页查询审核历史, pageParams={}", pageParams);
        return R.successDef(homeBuilderDrawingCategoryAuditHistoryService.listHistoryVO(pageParams));
    }
}
